<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
  
  <head>
    <meta charset="UTF-8">
    <title>权限页面-Long-admin</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link  th:href="@{/X-admin/css/font.css}" rel="stylesheet" type="text/css">
    <link  th:href="@{/X-admin/css/xadmin.css}" rel="stylesheet" type="text/css">
  </head>
  <body>
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">UPMS</a>
        <a>
          <cite>权限</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">&#x1002;</i></a>
    </div>
    <div class="x-body">
      <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so">
          <input type="text" name="name"  placeholder="请输入资源名" autocomplete="off" class="layui-input">
          <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>
      </div>
      <xblock>
        <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
        <button class="layui-btn" onclick="x_admin_show('添加权限','/resourceController/addPage',600,400)"><i class="layui-icon"></i>添加</button>
        <span class="x-right" style="line-height:40px">共有数据：100 条</span>
      </xblock>
      <table class="layui-table" id="resourceList" lay-filter="resourceList">

      </table>

    </div>

    <script type="text/javascript"  th:attr="src=@{/X-admin/lib/jquery-3.2.1.min.js}"></script>
    <script type="text/javascript"  th:attr="src=@{/X-admin/lib/layui/layui.js}"></script>
    <script type="text/javascript"  th:attr="src=@{/X-admin/js/xadmin.js}"></script>
    <script type="text/javascript"  th:attr="src=@{/js/hylUtil.js}"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </body>

</html>
<script type="text/html" id="barDemo">
  <div class="td-manage">

    <a title="编辑"  lay-event="edit"  title="编辑权限" href="javascript:;">
      <i class="layui-icon">&#xe642;</i>
    </a>

    <a title="删除" lay-event="del"  href="javascript:;">
      <i class="layui-icon">&#xe640;</i>
    </a>
  </div>

</script>

<script>
    var tableIns;

    layui.use(['table','jquery'], function(){
        var table = layui.table
        tableIns=table.render({
            elem: '#resourceList'
            ,url:'/resourceController/list'
            ,cellMinWidth: 80
            ,cols: [[
                {type:'numbers'}
                ,{type: 'checkbox'}
                ,{field:'id', title:'ID', width:100, unresize: true, sort: true}
                ,{field:'name', title:'资源名称'}
                ,{field:'typeName', title:'类型',with:60}
                ,{field:'pname', title: '父类资源', with:60}
                ,{field:'sysName', title: '所属系统名称'}
                ,{field:'url', title:'url',with:70}
                ,{field:'roleNames', title:'角色名称',with:60}
                ,{field:'remark', title:'描述',with:100}
                ,{fixed: 'right', width:150, align:'center', toolbar: '#barDemo'}
            ]]
            ,even:true
            ,page: true
            ,limits: [5, 7, 10]
            ,limit: 5 //每页默认显示的数量
        });

        //监听工具条
        table.on('tool(resourceList)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
//            var tr = obj.tr; //获得当前行 tr 的DOM对象
            if(layEvent === 'detail'){
                //查看
            }else if(layEvent === 'del'){ //删除
                layer.confirm('真的删除行么', function(index){
                    obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                    layer.close(index);
                    //向服务端发送删除指令
                    $.ajax({
                        type: 'POST',
                        url: "/resourceController/delete",
                        data: {"id":data.id},
                        success: function (result) {
                            if (result.success){
//                                parent.location.reload();
                                location.reload();
                            }else{
                                layer.msg(result.msg,"错误提示");
                            }
                        },
                        dataType: "json"
                    });
                });
            } else if(layEvent === 'edit'){
                //编辑

                //同步更新缓存对应的值
                obj.update({
                    username: '123'
                    ,title: 'xxx'
                });
            }
        });

    });

    function delAll (argument) {

        var data = tableCheck.getData();

        layer.confirm('确认要删除吗？'+data,function(index){
            //捉到所有被选中的，发异步进行删除
            layer.msg('删除成功', {icon: 1});
            $(".layui-form-checked").not('.header').parents('tr').remove();
        });
    }
</script>

<script type="text/javascript">
    layui.use('form', function(){
        var form = layui.form;

        //监听提交
        form.on('submit(sreach)', function(data){
            layer.msg(JSON.stringify(data.field));
            tableIns.reload({
                where:data.field
            });
            return false;
        });
    });
</script>